//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.yuebanmaoshare.file.ufop.autoconfiguration;

import com.github.tobato.fastdfs.FdfsClientConfig;
import com.yuebanmaoshare.file.ufop.factory.UFOPFactory;
import com.yuebanmaoshare.file.ufop.util.RedisUtil;
import com.yuebanmaoshare.file.ufop.util.UFOPUtils;
import com.yuebanmaoshare.file.ufop.util.concurrent.locks.RedisLock;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.context.annotation.Import;
import org.springframework.jmx.support.RegistrationPolicy;

@Configuration
@EnableConfigurationProperties({Properties.class})
@Import({FdfsClientConfig.class})
@EnableMBeanExport(
        registration = RegistrationPolicy.IGNORE_EXISTING
)
public class AutoConfiguration {
    private static final Logger log = LoggerFactory.getLogger(AutoConfiguration.class);
    @Autowired
    private Properties Properties;

    @Bean
    public UFOPFactory ufopFactory() {
        UFOPUtils.LOCAL_STORAGE_PATH = this.Properties.getLocalStoragePath();
        String bucketName = this.Properties.getBucketName();
        if (StringUtils.isNotEmpty(bucketName)) {
            UFOPUtils.ROOT_PATH = this.Properties.getBucketName();
        } else {
            UFOPUtils.ROOT_PATH = "upload";
        }

        return new UFOPFactory(this.Properties);
    }

    @Bean
    public RedisLock redisLock() {
        return new RedisLock();
    }

    @Bean
    public RedisUtil redisUtil() {
        return new RedisUtil();
    }
}
